this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,n,r,a,i,o,d){"use strict";var l,s;function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach((function(t){babelHelpers.defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var c=function(e){babelHelpers.inherits(i,e);function i(){var e;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,i);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(i).call(this,n));t.Dom.addClass(e.layout,"landing-ui-form-menu");e.forms=new BX.Landing.UI.Collection.FormCollection;if(t.Type.isArray(n.forms)){n.forms.forEach((function(t){e.addForm(t)}))}e.draggable=new d.Draggable({container:e.getBody(),context:parent.window,draggable:".landing-ui-form-menuitem",dragElement:".landing-ui-form-header-drag-button",type:d.Draggable.DROP_PREVIEW,depth:{margin:20},offset:{y:-65}});e.onMenuItemRemove=e.onMenuItemRemove.bind(babelHelpers.assertThisInitialized(e));t.Dom.append(e.getAddItemLayout(),e.layout);return e}babelHelpers.createClass(i,[{key:"addForm",value:function e(n){if(!this.forms.contains(n)){this.forms.add(n);t.Dom.append(n.layout,this.body);n.subscribe("remove",this.onMenuItemRemove.bind(this));if(this.draggable){this.draggable.invalidateCache()}}}},{key:"onMenuItemRemove",value:function e(n){var r=this.draggable.getChildren(n.data.form.layout);r.forEach((function(e){t.Dom.remove(e)}));this.forms.remove(n.data.form);this.draggable.invalidateCache()}},{key:"serialize",value:function e(){var t=this;var n=this.draggable.getDraggableElements();var r=function e(n){var r=t.draggable.getElementDepth(n);var a=t.draggable.getChildren(n);return a.reduce((function(n,a){var i=t.draggable.getElementDepth(a);if(i===r+1){var o=t.forms.getByLayout(a);n.push(u(u({},o.serialize()),{},{children:e(a)}))}return n}),[])};return n.reduce((function(e,n){if(t.draggable.getElementDepth(n)===0){var a=t.forms.getByLayout(n);e.push(u(u({},a.serialize()),{},{children:r(n)}))}return e}),[])}},{key:"onAddButtonClick",value:function e(t){t.preventDefault();var i=r.Env.getInstance().getType();var d={text:n.Loc.getMessage("LANDING_NEW_PAGE_LABEL"),target:"_blank",href:["KNOWLEDGE","GROUP"].includes(i)?"#landing0":""};var l=[BX.Landing.UI.Field.LinkUrl.TYPE_BLOCK,BX.Landing.UI.Field.LinkUrl.TYPE_PAGE,BX.Landing.UI.Field.LinkUrl.TYPE_CRM_FORM,BX.Landing.UI.Field.LinkUrl.TYPE_CRM_PHONE];if(i==="STORE"){l.push(BX.Landing.UI.Field.LinkUrl.TYPE_CATALOG)}var s=new BX.Landing.UI.Field.Link({content:d,options:{siteId:r.Env.getInstance().getSiteId(),landingId:a.Main.getInstance().id,filter:{"=TYPE":i}},allowedTypes:l});var g=new o.MenuItemForm({fields:[s]});g.showForm();this.addForm(g);setTimeout((function(){s.input.enableEdit();var e=s.input.input;var t=babelHelpers.slicedToArray(e.childNodes,1),n=t[0];if(n){var r=document.createRange();var a=window.getSelection();r.setStart(n,e.innerText.length);r.collapse(true);a.removeAllRanges();a.addRange(r)}}))}},{key:"getAddButton",value:function e(){var r=this;return this.cache.remember("addButton",(function(){return t.Tag.render(l||(l=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<button \n\t\t\t\t\tclass="ui-btn ui-btn-sm ui-btn-light-border ui-btn-icon-add ui-btn-round landing-ui-form-menu-add-button"\n\t\t\t\t\tonclick="','"\n\t\t\t\t\t>\n\t\t\t\t\t',"\n\t\t\t\t</button>\n\t\t\t"])),r.onAddButtonClick.bind(r),n.Loc.getMessage("LANDING_ADD_MENU_ITEM"))}))}},{key:"getAddItemLayout",value:function e(){var n=this;return this.cache.remember("addItemLayout",(function(){return t.Tag.render(s||(s=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-form-menu-add">\n\t\t\t\t\t',"\n\t\t\t\t</div>\n\t\t\t"])),n.getAddButton())}))}}]);return i}(i.BaseForm);e.MenuForm=c})(this.BX.Landing.UI.Form=this.BX.Landing.UI.Form||{},BX,BX.Landing,BX.Landing,BX.Landing,BX.Landing.UI.Form,BX.Landing.UI.Form,BX.UI.DragAndDrop);
//# sourceMappingURL=menuform.bundle.map.js